package tp.badugi.bot;

import static org.junit.Assert.*;

import java.util.Arrays;
import java.util.Set;
import java.util.TreeSet;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import com.sun.xml.internal.ws.util.StringUtils;

public class CardIntersectionTest {

	private BotCardInformationProvider botCardInformationProvider;
	
	@Before
	public void before() throws Exception {
		this.botCardInformationProvider = new BotCardInformationProvider();
	}
	
	@After
	public void after() throws Exception {
	}
	
	@Test
	public void Given_3C_5C_And_3C_3D_Expected_3C(){
		String[] givenCardSet1 = {"3C","5C"};
		String[] givenCardSet2 = {"3C","3D"};
		
		Set<String> expectedResult = new TreeSet<String>(Arrays.asList(new String[]{"3C"}));
		
		Set<String> botResult = this.botCardInformationProvider.getIntersection(givenCardSet1, givenCardSet2);
		
		assertTrue(expectedResult.containsAll(botResult) && botResult.containsAll(expectedResult));
	}
	
	@Test
	public void Given_AS_2S_3S_And_AD_AS_Expected_AS(){
		String[] givenCardSet1 = {"AS","2S","3S"};
		String[] givenCardSet2 = {"AS","AD"};
		
		Set<String> expectedResult = new TreeSet<String>(Arrays.asList(new String[]{"AS"}));
		
		Set<String> botResult = this.botCardInformationProvider.getIntersection(givenCardSet1, givenCardSet2);
		
		assertTrue(expectedResult.containsAll(botResult) && botResult.containsAll(expectedResult));
	}
	
	@Test
	public void Given_3D_3C_3S_And_3C_AC_Expected_3C(){
		String[] givenCardSet1 = {"3C","3D","3S"};
		String[] givenCardSet2 = {"3C","AC"};
		
		Set<String> expectedResult = new TreeSet<String>(Arrays.asList(new String[]{"3C"}));
		
		Set<String> botResult = this.botCardInformationProvider.getIntersection(givenCardSet1, givenCardSet2);
		
		assertTrue(expectedResult.containsAll(botResult) && botResult.containsAll(expectedResult));
	}
	
	@Test
	public void Given_AS_AC_AD_AH_And_Empty_Expected_Empty(){
		String[] givenCardSet1 = {"AS","AC","AD","AH"};
		String[] givenCardSet2 = new String[]{};
		
		Set<String> expectedResult = new TreeSet<String>(Arrays.asList(new String[]{}));
		
		Set<String> botResult = this.botCardInformationProvider.getIntersection(givenCardSet1, givenCardSet2);
		
		assertTrue(expectedResult.containsAll(botResult) && botResult.containsAll(expectedResult));
	}
	
	@Test
	public void Given_AS_AC_And_3S_3C_Expected_Empty(){
		String[] givenCardSet1 = {"AS","AC"};
		String[] givenCardSet2 = {"3S","3C"};
		
		Set<String> expectedResult = new TreeSet<String>(Arrays.asList(new String[]{}));
		
		Set<String> botResult = this.botCardInformationProvider.getIntersection(givenCardSet1, givenCardSet2);
		
		assertTrue(expectedResult.containsAll(botResult) && botResult.containsAll(expectedResult));
	}
	
	@Test
	public void Given_Empty_And_Empty_Expected_Empty(){
		String[] givenCardSet1 = new String[]{};
		String[] givenCardSet2 = new String[]{};
		
		Set<String> expectedResult = new TreeSet<String>(Arrays.asList(new String[]{}));
		
		Set<String> botResult = this.botCardInformationProvider.getIntersection(givenCardSet1, givenCardSet2);
		
		assertTrue(expectedResult.containsAll(botResult) && botResult.containsAll(expectedResult));
	}
	
	@Test
	public void Set_Result_To_String_Given_AS_AC_And_AC_3C_Expected_AC(){
		String[] givenCardSet1 = {"AS","AC"};
		String[] givenCardSet2 = {"AC","3C"};
		
		String expectedResult = "AC";
		
		Set<String> botResult = this.botCardInformationProvider.getIntersection(givenCardSet1, givenCardSet2);
		
		String botResultAsString = ((TreeSet<String>) botResult).first().toString();
		
		assertTrue(botResultAsString.equals(expectedResult));
	}
	
	@Test
	public void Set_Result_To_String_Given_KS_KC_And_5S_8S_Expected_Empty(){
		String[] givenCardSet1 = {"KS","KC"};
		String[] givenCardSet2 = {"5S","8S"};
		
		String expectedResult = "";
		
		Set<String> botResult = this.botCardInformationProvider.getIntersection(givenCardSet1, givenCardSet2);
		
		String botResultAsString;
		
		if(botResult.size() != 0){
			botResultAsString = botResult.iterator().next();
		}
		else{
			botResultAsString = "";
		}
		
		assertTrue(botResultAsString.equals(expectedResult));
	}

}
